package cn.leyaber.hrm.quartz;


import cn.leyaber.hrm.quartz.constants.JobTypeConsts;
import cn.leyaber.hrm.service.IOrderGoodsService;
import com.alibaba.fastjson.JSONObject;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 处理定时调度任务的统一入口
 * @author hm
 *
 */
public class MainJob implements Job {

   @Autowired
   private IOrderGoodsService orderGoodsService;

   @Override
   public void execute(JobExecutionContext context) throws JobExecutionException {
       String infoJsonStr = (String)context.getJobDetail().getJobDataMap().get("params");
       QuartzJobInfo info = JSONObject.parseObject(infoJsonStr, QuartzJobInfo.class);
         switch (info.getType()) {
            case JobTypeConsts.WAIT_PRODUCT_ORDER_PAY_CANCEL_JOB:
               Integer orderId = (Integer) info.getParams().get("orderId");
                orderGoodsService.cancelOrder(Long.parseLong(orderId.toString()));
               break;
            case JobTypeConsts.WAIT_GOODS_ORDER_PAY_CANCEL_JOB:
               System.out.println("商品订单支付取消。。。。");
               break;
            default:
               break;
         }
   }
}